require "/scripts/util.lua"

function build(directory, config, parameters, level, seed)
  config.inventoryIcon = jarray()

  table.insert(config.inventoryIcon, {
      image = string.format("%s?hueshift=%s", util.absolutePath(root.treeStemDirectory(parameters.stemName), "saplingicon.png"), parameters.stemHueShift or 0)
    })
	
  local titled = string.gsub(string.format(parameters.stemName), "^.", string.upper)
  parameters.shortdescription = "Sapling [" .. titled .. "]"

  if parameters.foliageName then
    table.insert(config.inventoryIcon, {
        image = string.format("%s?hueshift=%s", util.absolutePath(root.treeFoliageDirectory(parameters.foliageName), "saplingicon.png"), parameters.foliageHueShift or 0)
      })
  end


	saplings = {
		{ name = "Alienfruit Sapling", foliageName = {"alienbigleaf", "aliencircle"} },
		{ name = "Bio Sample Sapling", foliageName = {"jungleleaf"} },
		{ name = "Coconut Sapling", foliageName = {"cocopalm"} },
		{ name = "Eye Pile Sapling", foliageName = {"eyefoliage"} },
		{ name = "Flower Petal Sapling", foliageName = {"bluebell"} },
		{ name = "Geode Sapling", foliageName = {"geodefoliage"} },
		{ name = "Mushroom Sapling", stemName = {"mushroomstalk"} },
		{ name = "Plant Fibre Sapling", stemName = {"bladetree"} },
		{ name = "Red Apple Sapling", foliageName = {"redapple"} },

		{ name = "Banana Sapling", foliageName = {"bananatreeleaf"} },
		{ name = "Coconut Sapling", foliageName = {"coconut"} },
		{ name = "Red Apple Sapling", foliageName = {"apple"} },
		{ name = "Peach Sapling", foliageName = {"peach"} },
		{ name = "Pear Sapling", foliageName = {"pear"} },
		{ name = "Nyani String Sapling", foliageName = {"nyanifoliage"} },
		{ name = "Pearlfruit Sapling", foliageName = {"pearlfoliage"} },
		{ name = "Tearnut Sapling", foliageName = {"tearnutfoliage"} },
		{ name = "Bio Spore Sapling", foliageName = {"mushroomredtopbio", "mushroomyellowtopbio"} },
		{ name = "Putrid Slime Sapling", foliageName = {"edelwoodleaves"} },

		{ name = "Bamboo Shoot Sapling", stemName = {"bamboostem"} },
		{ name = "Genetic Material Sapling", stemName = {"doomwood"} },
		{ name = "Shiny Crystal Sapling", stemName = {"crystalline2", "crystalline3"} },
		{ name = "Flower Petal Sapling", stemName = {"giantflower"} }
	}


	if parameters then
		for position, item in pairs(parameters) do
			for k, v in pairs(saplings) do
				if position == "foliageName" and v.foliageName then
					for i, j in pairs(v.foliageName) do
						if item == j then
							parameters.shortdescription = v.name
							parameters.foliageHueShift = v.foliageHueShift or 0
							parameters.stemHueShift = v.stemHueShift or 0
						end
					end
				end
				if position == "stemName" and v.stemName then
					for o, p in pairs(v.stemName) do
						if item == p then
							parameters.shortdescription = v.name
							parameters.foliageHueShift = v.foliageHueShift or 0
							parameters.stemHueShift = v.stemHueShift or 0
						end
					end
				end
			end
		end
	end

  return config, parameters
end